﻿using Architecture.API.Application.Command.CountyCommand;
using Architecture.Domain;
using Architecture.Domain.Service.CountyService;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.CountyHandler
{
    /// <summary>
    /// 县区查询命令处理器
    /// </summary>
    public class CountySearchCommandHandler : IRequestHandler<CountySearchCommand, List<County>>
    {
        /// <summary>
        /// 县区服务
        /// </summary>
        private readonly ICountyService _countyService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="countyService">县区服务</param>
        public CountySearchCommandHandler(ICountyService countyService)
        {
            _countyService = countyService;
        }

        /// <summary>
        /// 县区查询命令处理器
        /// </summary>
        /// <param name="request">请求到的CityId</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回查询到的县区列表</returns>
        public async Task<List<County>> Handle(CountySearchCommand request, CancellationToken cancellationToken)
        {
            return await _countyService.GetAllCounties(request.CityId);
        }
    }
}
